package com.link2room.bumblebee.controller.inside;

import com.link2room.bumblebee.dto.param.base.CodeBaseParamDto;

import com.link2room.bumblebee.facade.ICodeBaseFacadeService;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.result.base.SysOptionDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by LN on 2017/4/13.
 */
@Api(tags = "基础代码")
@RestController
@RequestMapping("/in/BaseCodes")
public class BascCodeInsideController {
    @Resource
    private ICodeBaseFacadeService codeBaseFacadeService;

    @ApiOperation(value = "获取基础代码", response = SysOptionDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "codes",value = "代码", paramType = "query", required = true),
    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto getBaseCode(
            @RequestParam(name = "codes" ,required = true) List<String> codes
    ) throws Exception {
        CodeBaseParamDto paramDto = new CodeBaseParamDto();
        paramDto.setCodes(codes);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultInfo(codeBaseFacadeService.findByCode(paramDto));
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "获取基础代码树结构", response = SysOptionDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "parentCode",value = "根节点代码", paramType = "query", required = true),
    })
    @RequestMapping(value = "/root",method = RequestMethod.GET)
    public BaseResultDto getRoots(
            @RequestParam(name = "parentCode" ,required = true) List<String> parentCodes
    ) throws Exception {
        CodeBaseParamDto paramDto = new CodeBaseParamDto();
        paramDto.setCodes(parentCodes);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultInfo(codeBaseFacadeService.findByCodeAsRoot(paramDto));
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
